package com.example.eos.controller;

import com.example.eos.bean.*;
import com.example.eos.service.PublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class PublishController {

    private PublishService publishService;

    @Autowired
    public PublishController(PublishService publishService){
        this.publishService = publishService;
    }

    //查询作品列表
    @RequestMapping(value = "/publishs", method = RequestMethod.GET)
    public ReturnInfo findPublishs(@RequestParam(value="labelname",required = false,defaultValue = "null") String labelname){
        return publishService.findPublishs(labelname);
    }

    //查询作品
    @RequestMapping(value = "/publish/{publishid}",method = RequestMethod.GET)
    public ReturnInfo lookPublish(@PathVariable String publishid){
        return publishService.lookPublish(publishid);
    }

    //新建作品
    @RequestMapping(value = "/publish",method = RequestMethod.POST)
    public ReturnInfo creatPublish(@RequestBody Publish publish){
        return publishService.creatPublish(publish);
    }

    //删除作品
    @RequestMapping(value = "/publish/{publishid}", method = RequestMethod.DELETE)
    public ReturnInfo detelePublish(@PathVariable String publishid){
        return publishService.detelePublish(publishid);
    }

    //点赞作品
    @RequestMapping(value = "/publish/{publishid}", method = RequestMethod.PUT)
    public ReturnInfo likePublish(@PathVariable String publishid){
        return publishService.likePublish(publishid);
    }
}
